package firefighter;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author matt
 */
public class Firefighter extends MIDlet implements Runnable {
    private MainMenu mainMenu;
    private HiScores hiScores;
    private boolean initDone = false;
    
    public Firefighter(){
        
    }
    
    public void startApp() {
        Displayable current = Display.getDisplay(this).getCurrent();
        if (current == null)
        {
            Display.getDisplay(this).setCurrent(new Splash(this));
        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void run()
    {
        init();
    }

    void splashScreenPainted()
    {
        new Thread(this).start();
    }

    void splashScreenDone()
    {
        init();
        Display.getDisplay(this).setCurrent(mainMenu);
    }

    static Image createImage(String filename)
    {
        Image image = null;
        try
        {
            image = Image.createImage(filename);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return image;
    }

    private synchronized void init()
    {
        if (!initDone)
        {
            mainMenu = new MainMenu(this);
            hiScores = new HiScores(this);
            initDone = true;
        }
    }

    void exit()
    {
        System.gc();    // garbage collect
        destroyApp(true);
        notifyDestroyed();
    }

    void mainMenuNewGame()
    {

    }

    void mainMenuContinue()
    {

    }

    void mainMenuHelp()
    {

    }

    void mainMenuExit()
    {
        exit();
    }

    void mainMenuHiScores()
    {
        Display.getDisplay(this).setCurrent(hiScores);
    }

    void hiScoresBack()
    {
        Display.getDisplay(this).setCurrent(mainMenu);
    }
}
